<?php

namespace traits;

use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Signer\Key;
use think\facade\Env;

// TODO 暂时不使用
trait JwtAuthModelTrait
{
    /**
     * @title 获取token值
     */
    public function getToken()
    {
        $id = $this->{$this->getPk()};
        $host = app()->request->host();
        $time = time();
        $exp = strtotime("+ 3hour");

        return (new Builder())
            ->issuedBy($host) // 颁发者
            ->permittedFor($time)
            ->identifiedBy($time, true)
            ->issuedAt($host)
            ->canOnlyBeUsedAfter($time)
            ->expiresAt($exp)
            ->withClaim("uid", $id)
            ->getToken(new Sha256(), new Key(Env::get('app.app_key', 'default')));
    }

    /**
     * @title 解析token
     */
    public static function parseToken()
    {

    }
}